from typing import Optional, TypeVar, Generic
from pydantic import BaseModel as GenericModel
from time import time

from pydantic import BaseModel

T = TypeVar("T")



class ResponseSchemaBase(BaseModel):
    __abstract__ = True

    code: str = ''
    message: str = ''
    t_ : int = int(time())

    def custom_response(self, code: str, message: str):
        self.code = code
        self.message = message
        self.t_ = int(time())
        return self

    def success_response(self):
        self.code = '200'
        self.message = 'Successful'
        self.t_ = int(time())
        return self


class DataResponse(ResponseSchemaBase, GenericModel, Generic[T]):
    data: Optional[T] = None

    class Config:
        arbitrary_types_allowed = True

    def custom_response(self, code: str = "200", message: str = "successful!", data: T = ""):
        self.code = code
        self.message = message
        self.data = data
        self.t_ = int(time())
        return self

    def success_response(self, data: T):
        self.code = '200'
        self.message = 'successful!'
        self.data = data
        self.t_ = int(time())
        return self


class MetadataSchema(BaseModel):
    current_page: int
    page_size: int
    total_items: int
